home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / winpos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  3.0 KB  |  122 lines

  1. /* $Id: winpos.c,v 1.2 1996/09/15 01:50:05 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: winpos.c,v $
  26.  * Revision 1.2  1996/09/15 01:50:05  brianp
  27.  * fixed #includes
  28.  *
  29.  * Revision 1.1  1996/09/13 01:38:16  brianp
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. /*
  36.  * GL_MESA_window_pos extension
  37.  *
  38.  * This extension offers a set of functions named glWindowPos*MESA() which
  39.  * directly set the current raster position to the given window coordinate.
  40.  * glWindowPos*MESA() are similar to glRasterPos*() but bypass the
  41.  * modelview, projection and viewport transformations.
  42.  *
  43.  * These functions should be very handy in conjunction with glDrawPixels()
  44.  * and glCopyPixels().
  45.  *
  46.  * If your application uses glWindowPos*MESA() and may be compiled with
  47.  * a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files
  48.  * into your source tree and compile them with the rest of your code
  49.  * since glWindowPos*MESA() can, and is, implemented in terms of standard
  50.  * OpenGL commands when not using Mesa.  In your source files which use
  51.  * glWindowPos*MESA() just #include "winpos.h".
  52.  */
  53.  
  54.  
  55.  
  56. #include "GL/gl.h"
  57.  
  58.  
  59. #ifdef GL_MESA_window_pos
  60.  
  61.  
  62. #include "draw.h"
  63. #include "dlist.h"
  64. #include "macros.h"
  65. #include "types.h"
  66. #include "winpos.h"
  67.  
  68.  
  69.  
  70. /*
  71.  * Mesa implementation of glWindowPos*MESA()
  72.  */
  73. void gl_WindowPos4fMESA( GLcontext *ctx,
  74.                          GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  75. {
  76.    gl_windowpos( ctx, x, y, z, w );
  77. }
  78.  
  79.  
  80. #else
  81.  
  82.  
  83. /*
  84.  * OpenGL implementation of glWindowPos*MESA()
  85.  */
  86. void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  87. {
  88.    GLfloat fx, fy;
  89.  
  90.    /* Push current matrix mode and viewport attributes */
  91.    glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
  92.  
  93.    /* Setup projection parameters */
  94.    glMatrixMode( GL_PROJECTION );
  95.    glPushMatrix();
  96.    glLoadIdentity();
  97.    glMatrixMode( GL_MODELVIEW );
  98.    glPushMatrix();
  99.    glLoadIdentity();
  100.  
  101.    glDepthRange( z, z );
  102.    glViewport( (int) x - 1, (int) y - 1, 2, 2 );
  103.  
  104.    /* set the raster (window) position */
  105.    fx = x - (int) x;
  106.    fy = y - (int) y;
  107.    glRasterPos4f( fx, fy, 0.0, w );
  108.  
  109.    /* restore matrices, viewport and matrix mode */
  110.    glPopMatrix();
  111.    glMatrixMode( GL_PROJECTION );
  112.    glPopMatrix();
  113.  
  114.    glPopAttrib();
  115. }
  116.  
  117.  
  118. #endif
  119.  
  120.  
  121.  
  122.